package com.sxkf.template.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxkf.core.api.vo.R;
import com.sxkf.template.entity.Prize;
import com.sxkf.template.entity.UserPrize;
import com.sxkf.template.service.UserPrizeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.xml.ws.Action;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杨玉龙
 * @since 2025-01-04 18:08:25
 */
@RestController
@RequestMapping("/userPrize")
public class UserPrizeController {
    @Resource
    private UserPrizeService userPrizeService;

    @ApiOperation(value = "查询用户奖品")
    @GetMapping(value = "/page")
    public R<IPage<UserPrize>> page(@RequestParam Integer pageNo,@RequestParam Integer pageSize,@RequestParam String userId){
        Page<UserPrize> page = userPrizeService.page(new Page<>(pageNo, pageSize), new LambdaQueryWrapper<UserPrize>().eq(UserPrize::getUserId, userId).orderByDesc(UserPrize::getCreateTime));
        return R.success(page);
    }


    @ApiOperation(value = "抽奖")
    @PostMapping(value = "/lottery")
    public R<Prize> lottery(@RequestParam String userId){
        return R.success(userPrizeService.lottery(userId));
    }
}
